package com.sfh.cp.msg;

import android.text.Html;
import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sfh.cp.R;

import crm.sfh.server.entity.ENotice;
import crm.sfh.server.entity.ETopic;

import com.squareup.picasso.Picasso;

/**
 * Created by Administrator on 2018/3/14.
 */

public class MessageAdapter extends BaseQuickAdapter<ENotice, BaseViewHolder> {
    public MessageAdapter() {
        super(R.layout.message_recycle_adapter);
    }

    @Override
    protected void convert(BaseViewHolder helper, ENotice item) {

        helper.setText(R.id.tvTitle, Html.fromHtml(getTitle(item)));
        helper.setText(R.id.tvTime, item.getCreateTime());

        ImageView ivLW = helper.getView(R.id.ivLW);

        if (TextUtils.isEmpty(item.getFromUserHead())) {
            ivLW.setImageResource(R.mipmap.songli_chat);
        } else {
            Picasso.with(ivLW.getContext()).load(item.getGiftUrl()).into(ivLW);
        }

        ImageView ivLeft = helper.getView(R.id.ivLeft);

        if (TextUtils.isEmpty(item.getFromUserHead())) {
            ivLeft.setImageResource(R.mipmap.userimg_default);
        } else {
            Picasso.with(ivLeft.getContext()).load(item.getFromUserHead()).into(ivLeft);
        }

        ImageView ivRight = helper.getView(R.id.ivRight);
        if (TextUtils.isEmpty(item.getFromUserHead())) {
            ivRight.setImageResource(R.mipmap.userimg_default);
        } else {
            Picasso.with(ivRight.getContext()).load(item.getToUserHead()).into(ivRight);
        }

        if (TextUtils.equals("0",item.getGiftType())){
            helper.setVisible(R.id.tvValue,false);
        }else{
            helper.setVisible(R.id.tvValue,true);
            helper.setText(R.id.tvValue,item.getTypeText());
        }

    }

    private String getTitle(ENotice item) {
       return  "<font  color=\"#666666\">"+ item.getFromUserName() +"给"+item.getToUserName()+"赠送了</font><font  color=\"#FF4081\">"+item.getGiftName()+"x"+item.getGiftCharm()+"</font>";
    }
}
